import {
  Controller,
  Post,
  UploadedFile,
  UseGuards,
  UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { AuthGuard } from '../guards/authority.guard';
import { ApiBody, ApiConsumes, ApiOperation, ApiTags } from '@nestjs/swagger';
import { FileUploadDto } from '../dtos/fileUpload.dto';
import { imgUrl } from '../config/config';
import { AuthorBaseControll } from './authorBase.controller';

@Controller('/uploadFile')
@UseGuards(AuthGuard)
@ApiTags('文件上传')
export class UploadFileController extends AuthorBaseControll {
  @Post('/singleUploadFile')
  @ApiOperation({ summary: '单文件上传' })
  @UseInterceptors(FileInterceptor('file'))
  @ApiConsumes('multipart/form-data')
  @ApiBody({
    description: '单文件上传',
    type: FileUploadDto,
  })
  async singleUploadFile(@UploadedFile() file) {
    const filePath = imgUrl + file.path.replace(/\\/g, '/');
    return {
      filePath: filePath,
    };
  }
}
